import { getAction,postAction } from "@/api/manage";
export default {
  components: {
    AgForm: () => import("@/components/AgForm/AgForm.vue"),
    AgModalForm: () => import("@/components/AgForm/AgModalForm.vue")
  },
  data() {
    return {
      queryParam:{},//查询参数
      loading: false,//列表数据加载
      columns: [], //表头
      scroll:{ x: 1000, y: 500 },//滚动条设置
      pagination: { //分页数据
        size: "small",
        defaultPageSize: 20,
        current: 1,
        pageSize: 20,
        total: 0,
        showTotal: total => {
          return (
            <div>
              共 {total} 条数据，每页
              <a-input style="height:22px !important;width:3.2rem;"
                value={this.pagination.pageSize}
                min={1}
                max={500}
                size="small"
                step={1}
                onPressEnter={e => this.changePageSize(e)}
              />
              条
            </div>
          );
        },
        showQuickJumper: true,
        showLessItems: true
      },
      dateSource: [],//表格数据
      selectedRowKeys: [],//table选中keys
      selectedRows: [],//table选中records
      isorter: {},//排序参数
      
    }
  },
  methods: {
    //改变分页大小
    changePageSize(e) {
      const value = e.target.value;
      let size = Number.parseInt(value);
      if(!size){
          size = 20;
      }
      if(size > 500){
          size = 500;
      }
      // console.log(e, value);
      // Object.assign(this.postData.page, {
      //     current:1,
      //     size
      // });
      Object.assign(this.pagination, {
          current:1,
          pageSize: size
      });
      console.log("改变分页大小_pagelist")
      this.loadData();
  },
    //分页、排序、筛选变化时触发
    onTableChange(pagination, filters, sorter) {
      console.log(sorter);
      
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field;
        this.isorter.order = 'ascend' == sorter.order ? 'asc' : 'desc';
      }
      this.pagination = pagination;
      this.loadData();
    },
    //选择表格项
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
    },
 
    //公共加载数据方法
    loadData(arg){
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!');
        return;
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.pagination.current = 1;
      }
      var params = {}; //查询条件
      this.loading = true;
      getAction(this.url.list, params).then(res => {
        console.log(res)
        if (res.code == 200) {
          this.dataSource = res.data;
          this.pagination.total = res.data.length;
        }else{
          // this.$message.warning(res.message);
        }
        this.loading = false;
      })
    }

  },
  created() {
    this.loadData(1);
  }
}